﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    public class FaTieDAL
    {
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public static List<FaTie> SelectAlly()
        {
            string sql = "select f.FaTieTypeTitle,f.FaTieTypeid,f.FaTieContent,f.FaTieTime,f.DianJiRate,y.UserName,f.FaTieID from FaTie f,Yonghu y where f.UserID=y.UserID";
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            List<FaTie> list = new List<FaTie>();
            foreach (DataRow item in dt.Rows)
            {
                FaTie model = new FaTie();
                model.FaTieID = Convert.ToInt32(item["FaTieID"]);
                model.UserID = Convert.ToInt32(item["UserID"]);
                model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
                model.FaTieTypeid = Convert.ToInt32(item["FaTieTypeid"]);
                model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
                model.FaTieContent = item["FaTieContent"].ToString();
                model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
                list.Add(model);
            }
            return list;
        }
        /// <summary>
        /// 查询标题
        /// </summary>
        /// <param name="fatie"></param>
        /// <returns></returns>
        public static DataTable SelectBiaoti(FaTie fatie)
        {
            string sql = string.Format("select f.FaTieTypeTitle,f.FaTieTime,f.DianJiRate,y.UserName from FaTie f,Yonghu y where f.UserID=y.UserID and f.FaTieTypeTitle like '%{0}%'", fatie.FaTieTypeTitle);
            return DBHelper.Instance().GetDataTableBySql(sql);
        }
    }
}
